<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="database" scope="request"
    class="accessibleworldsdatabase.AccessibleWorldsDatabaseJavaBeans" />
<jsp:useBean id="des" scope="request"
    class="accessibleworldsdes.AccessibleWorldsDESJavaBeans" />
<%
    database.connect(des.decryptString(des.getServiceSecretKey(),
            database.getEncryptedPassword()));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User Profile</title>
</head>
<body>

	<%
		String username=request.getParameter("username");
		
		if(username==null)
			username=(String)request.getSession().getAttribute("username");
		System.out.println(username);
		String password = request.getParameter("password");

		if(password==null)
			password=(String)request.getSession().getAttribute("password");
		System.out.println(password );

		try{
			
			String SQL =
		            "SELECT * FROM Users"+
		            	" WHERE"+
		            		" email = '"+username+"'"+
		            		" AND password = '"+password+"'"+
		            		" AND U_type = '0'";
			
			ResultSet rs= database.execSQL(SQL);
			
			if(rs.next()){
				
				session.setAttribute( "username", username );
				session.setAttribute( "password", password );
				
				System.out.println("qq");
				
				%>
				
	<br>
	<br>
	<br>
	<br>
	<br>
	<br>

	<div id="wrapper">
		<div id="hi">
			<p style="font-size: 24px;">
				<b>Hello <%=username%></b>
			</p>
			
		</div>
		
		<div>
		
		<% 
		String SQLmessages = "SELECT `Admin_Messages` . * , `Users`.`Email`FROM `Admin_Messages`LEFT JOIN `database5`.`Users` ON `Admin_Messages`.`User_id` = `Users`.`User_id`";
		
		ResultSet rsMessages=database.execSQL(SQLmessages);
		ArrayList<String> messages=new ArrayList<String>();
		ArrayList<String> topics=new ArrayList<String>();
		ArrayList<String> ids=new ArrayList<String>();
		ArrayList<String> users=new ArrayList<String>();
		
		if(rsMessages.next())
		{  
			do{
				topics.add(rsMessages.getString("Topic"));
				messages.add(rsMessages.getString("Message"));
				ids.add(rsMessages.getString("Message_ID"));
				users.add(rsMessages.getString("Email"));
				 
			}while (rsMessages.next());
		%>
			
			<table class="table">
				<thead>
				<tr>
					<th> Topic </th>
					<th> Message </th>
					<th> User mail</th>
					<th> Delete </th>
				</tr>
				
				</thead>
				<tbody>
				
			
		<%}else{ %>
		
		<p> NO PENDING MESSAGES.</p>
	
		<%	
		}
		 for(int i=0;i<messages.size();i++){
			 %> 
				<tr>
					<th> <%= topics.get(i) %> </th>
					<th> <%= messages.get(i) %> </th>
					<th> <%= users.get(i) %> </th>
					<th> <form action="deleteMessage.jsp" method="post">
							<input type="hidden" name="deleteID"
											value= "<%= ids.get(i) %>"><input
											type="submit" value="Delete"> </form>
					
											</th>
				</tr>
				
				<%
			 
		 }
		%>
		</tbody>
		</table>
		</div>
	</div>
	<br>
	<br>
	<br>
	<hr>

	<%}else{%>
	<div>
		<h1 >
			Wrong password or username.</h1>
		<br>
		<br>
		<a href="index.jsp">Return to Main Page.</a>
	</div>
	<%}
		}catch(Exception e){
			e.printStackTrace();%>
	<div>
		<h1 >
			Wrong password or username.</h1>
		<br>
		<br>
		<a href="index.jsp">Return to admin panel login page.</a>
	</div>
	<%};
		%>

</body>
</html>